<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
		    <el-form-item label="内容">
				<el-button size="mini" @click="isShow=true" type="primary">选择图片</el-button>
			</el-form-item>
			<el-form-item v-if="form.content">
			  <div style="display: flex;">
				  <div style="position: relative;margin-right: 10px;" 
					v-for="(el,i) in form.content"
					:key="i"
					>
					  <img style="width: 100px;height: 100px;" :src="el" alt="">
					  <i @click="delImg(i)" class="el-icon-circle-close" style="font-size: 20px;position: absolute;top: 0;right:0;cursor: pointer;"></i>
				  </div>
			  </div>
		    </el-form-item>
			<el-form-item label="状态">
			  <el-radio-group ref="radio" v-model="form.status">
				<el-radio label="0">禁用</el-radio>
				<el-radio label="1">启用</el-radio>
			  </el-radio-group>
			</el-form-item>
			<el-form-item label="排序">
				<el-input size="mini"
					type="number"
					v-model="form.sort"></el-input>
			</el-form-item>
			<el-form-item >
			  <el-button type="primary" @click="confirm" size="small">确定</el-button>
		    </el-form-item>
		</el-form>
		
		<el-dialog title="选择图片"
				:close-on-click-modal="false"
				:modal-append-to-body="false"
				:append-to-body="true"
				:visible.sync="isShow"
				width="1050px">
			 <div style="padding-bottom: 30px;">
				 <imgSys @getImgData="getImgData" />
			 </div>
			 
		</el-dialog>
	</div>
</template>

<script>
	import imgSys from '@/components/imgSys'
	export default {
		components:{
			imgSys
		},
		props:{
			formDD:{
				type:Object,
				default:{}
			}
		},
		mounted() {
			// 获取到带有aria-hidden属性的元素
			  const ariaEls = this.$refs.radio.$el.querySelectorAll('input[type="radio"]')
			  if (!ariaEls) return
			  ariaEls.forEach((item) => {
			    // aria-hidden属性
			    item.removeAttribute('aria-hidden');
			  });
			setTimeout(()=>{
				if(this.formDD.content){
					this.form.content = JSON.parse(this.formDD.content)
				}
				this.form.status = this.formDD.status
				this.form.sort = this.formDD.sort
			},100)
		},
		data(){
			return {
				isShow:false,
				form:{
					content:[],
					status:'1',
					sort:1
				}
			}
		},
		methods:{
			getImgData(val){
				this.form.content.push(val)
				this.isShow = false
			},
			delImg(i){
				this.form.content.splice(i,1)
			},
			confirm(){
				let params = {
					content:JSON.stringify(this.form.content),
					status:this.form.status,
					sort:this.form.sort,
					cid:sessionStorage.getItem('cid')
				}
				this.$emit('getFormVal',params)
			},
		}
	}
</script>

<style>
	
</style>